package com.gxuwz.medical.web.servlet;

import java.io.IOException;
import java.util.Date;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.gxuwz.medical.domain.chronicCard.ChronicCard;
import com.gxuwz.medical.domain.chronicdis.Chronicdis;
import com.gxuwz.medical.domain.person.Person;
import com.gxuwz.medical.domain.register.Register;


/**
 * 
 * @author 沉羽墨玖
 *
 */
public class ChronicCardServlet extends BaseServlet {

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		this.doPost(req, resp);
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		String m=req.getParameter("m");
		try{
	    if("list".equals(m)){
	      process(req, resp, "/page/chronicCard/chronicCard_list.jsp");
	    }else if("input".equals(m)){
		  process(req, resp, "/page/chronicCard/chronicCard_add.jsp");
		}else if("get".equals(m)){
			  process(req, resp, "/page/chronicCard/chronicCard_edit.jsp");
		}else if("add".equals(m)){
			add(req, resp);
		}else if("edit".equals(m)){
			edit(req, resp);
		}else if("del".equals(m)){
			del(req, resp);
		}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	
	private void add(HttpServletRequest req,HttpServletResponse resp)throws ServletException,IOException{
  	  String id=req.getParameter("id");
  	  String persCode=req.getParameter("persCode");
  	  String persName=req.getParameter("persName");
  	  String cardId=req.getParameter("cardId");
  	  String illName=req.getParameter("illName");
  	  String startTime=req.getParameter("startTime");
	  String endTime=req.getParameter("endTime");
  	  //ʵ���������Բ�֤����
	  ChronicCard chronicCard=new ChronicCard();
	//������������θ�ֵ��ʵ���ĳ�Ա����
	  chronicCard.setId(id);
	  chronicCard.setPersCode(persCode);
	  chronicCard.setPersName(persName);
	  chronicCard.setCardId(cardId);
	  chronicCard.setIllName(illName);
	  chronicCard.setStartTime(startTime);
	  chronicCard.setEndTime(endTime);
  	  try{
  		chronicCard.add();
  		process(req, resp, "/page/chronicCard/chronicCard_list.jsp");
  	  }catch(Exception e){
  		e.printStackTrace();
  	  }
	
  
	}
	/**
	 * �޸����Բ�֤
	 * @param req
	 * @param resp
	 * @throws Exception 
	 */
	private void edit(HttpServletRequest req,HttpServletResponse resp)throws ServletException,Exception{

	  	String id=req.getParameter("id");
	  	String persCode=req.getParameter("persCode");
	  	String persName=req.getParameter("persName");
	  	String cardId=req.getParameter("cardId");
	  	String illName=req.getParameter("illName");
		String startTime=req.getParameter("startTime");
		String endTime=req.getParameter("endTime");
	  	  //2:构�?新慢病信息对�?
	  	ChronicCard chronicCard=new ChronicCard(id,persCode,persName,cardId, illName, startTime, endTime);
	  	  //3：调用保存的方法
	  	  try{
	  		chronicCard.edit();
	  		process(req, resp, "/page/chronicCard/chronicCard_list.jsp");
	  	  }catch(Exception e){
	  		e.printStackTrace();
	  	  }
		
	  
		}
	/**
	 * 删除慢�?病信�?
	 * @param req
	 * @param resp
	 * @throws ServletException
	 * @throws IOException
	 */
	private void del(HttpServletRequest req,HttpServletResponse resp)throws ServletException,IOException{
	  	  String id=req.getParameter("id");
	  	ChronicCard chronicCard=new ChronicCard();
	  	  try{
	  		System.out.println(id);
	  		chronicCard.del(id);
	  		process(req, resp, "/page/chronicCard/chronicCard_list.jsp");
	  	  }catch(Exception e){
	  		e.printStackTrace();
	  	  }
	  
		}

}
